package com.serviceImpl;

import com.query.StudentQuery;
import com.qzw.common.data.BaseMysqlDao;
import com.qzw.common.service.BaseServiceImpl;
import com.service.IStudentService;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Optional;
import com.dao.StudentDao;
import com.model.Student;
import java.lang.String;
import java.lang.Integer;
import com.entity.GoStudent;

@Service
public class StudentServiceImpl extends BaseServiceImpl<Student, GoStudent, Integer, StudentQuery> implements IStudentService {

	@Autowired
	private StudentDao dao;

	@Override protected BaseMysqlDao getDao() {
	return dao;
	}

	@Override
	public Student entity2model(GoStudent entity) {
		Student model = null;
		if(isNotEmpty(entity)){
			model = new Student();
			model.setId(entity.getId());
			model.setTest(entity.getTest());
		}
		return model;
	}

	@Override
	public GoStudent model2Entity(Student model) {
		GoStudent entity = null;
		if(isNotEmpty(model)){
			entity = new GoStudent();
			entity.setId(model.getId());
			entity.setTest(model.getTest());
		}
		return entity;
	}

	@Override
	public Student update(Student model) {
		if(model.isNew()){
			model = super.add(model);
		} else {
			Optional<GoStudent> entityOptional = dao.findById(model.getId());GoStudent entity = entityOptional.get();
			if(isNotEmpty(model.getTest()))
				entity.setTest(model.getTest());
			model = entity2model(dao.save(entity));
		}
		return model;
	}


}